/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import model.Cliente;
import model.Filme;
import model.Locacao;
import IRepositorios.IRepositorioCliente;
import IRepositorios.IRepositorioFilme;
import IRepositorios.IRepositorioOperacao;
import control.Locadora;
import control.dao.NotaFiscal;
import control.dao.metodosClientes;
import control.dao.metodosDVD;
import control.dao.metodosFilme;
import control.dao.metodosOperacao;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import model.DVD;

/**
 *
 * @author Andre
 */
public class FormLocacao extends javax.swing.JFrame {

    private Locadora loc;
    private IRepositorioFilme IRFilme;
    DefaultTableModel tmFilme = new DefaultTableModel(null, new String[]{"Título"});
    private List<DVD> listFilme;
    ListSelectionModel lsmFilme;
    private IRepositorioCliente IRCliente;
    DefaultTableModel tmCliente = new DefaultTableModel(null, new String[]{"Nome"});
    private List<Cliente> listCliente;
    ListSelectionModel lsmCliente;
    private IRepositorioOperacao IROperacao;
    DefaultTableModel tmOperacao = new DefaultTableModel(null, new String[]{"Nome cliente", "Titulo Filme", "Ativo"});
    private List<Locacao> listOperacao;
    ListSelectionModel lsmOperacao;
    static File arquivo;
    private NotaFiscal notaFiscal;
    private metodosDVD IRDVDs;
    public FormLocacao() {
        initComponents();
        BufferedImage image = null;
        File imageFile = new File(".\\src\\Imagens\\logo.png");
        try {
            image = ImageIO.read(imageFile);

        } catch (IOException ex) {
        }
        this.setIconImage(image);

        IRCliente = new metodosClientes();
        IRFilme = new metodosFilme();
        IROperacao = new metodosOperacao();
        notaFiscal = new NotaFiscal();
        IRDVDs = new metodosDVD();
        loc = new Locadora(IRFilme, IRCliente, IROperacao, notaFiscal, IRDVDs );

        listCliente = loc.buscarClienteList(jTF_pesquisarCliente.getText() + "%");
        mostraPesquisaCliente(listCliente);

        listFilme = loc.buscarListaDVDs(jTF_pesquisarFilme.getText() + "%");
        jRB_sim.isSelected();


        mostraPesquisaFilme(listFilme);

        jTF_pesquisarKeyReleased(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jDialog1 = new javax.swing.JDialog();
        jFileChooser1 = new javax.swing.JFileChooser();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTabela_Filme = new javax.swing.JTable();
        jTF_pesquisarFilme = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTF_pesquisarCliente = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTabela_Cliente = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jFTF_data = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jRB_sim = new javax.swing.JRadioButton();
        jRB_nao = new javax.swing.JRadioButton();
        jB_salvar = new javax.swing.JButton();
        jB_devolver = new javax.swing.JButton();
        jB_novo = new javax.swing.JButton();
        jB_voltar1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTabela_Operacao = new javax.swing.JTable();
        jTF_pesquisar = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jFTF_data_devolucao = new javax.swing.JFormattedTextField();

        jLabel1.setText("jLabel1");

        jLabel2.setText("jLabel2");

        jFileChooser1.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Locação");
        getContentPane().setLayout(null);

        jTabela_Filme.setModel(tmFilme);
        jTabela_Filme.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmFilme = jTabela_Filme.getSelectionModel();
        lsmFilme.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    JTTabelaLinhaSelecionadaFilme(jTabela_Filme);
                }
            }
        }
    );
    jScrollPane2.setViewportView(jTabela_Filme);

    getContentPane().add(jScrollPane2);
    jScrollPane2.setBounds(310, 70, 220, 120);

    jTF_pesquisarFilme.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            jTF_pesquisarFilmeKeyReleased(evt);
        }
    });
    getContentPane().add(jTF_pesquisarFilme);
    jTF_pesquisarFilme.setBounds(370, 40, 160, 20);

    jLabel16.setText("Pesquisar:");
    getContentPane().add(jLabel16);
    jLabel16.setBounds(310, 40, 60, 20);

    jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Selecione um Filme", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
    getContentPane().add(jLabel3);
    jLabel3.setBounds(290, 10, 260, 200);

    jTF_pesquisarCliente.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTF_pesquisarClienteMouseClicked(evt);
        }
    });
    jTF_pesquisarCliente.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            jTF_pesquisarClienteKeyReleased(evt);
        }
    });
    getContentPane().add(jTF_pesquisarCliente);
    jTF_pesquisarCliente.setBounds(90, 40, 160, 20);

    jLabel17.setText("Pesquisar:");
    getContentPane().add(jLabel17);
    jLabel17.setBounds(30, 40, 60, 20);

    jTabela_Cliente.setModel(tmCliente);
    jTabela_Cliente.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lsmCliente = jTabela_Cliente.getSelectionModel();
    lsmCliente.addListSelectionListener(new ListSelectionListener(){
        public void valueChanged(ListSelectionEvent e){
            if(! e.getValueIsAdjusting()){
                JTTabelaLinhaSelecionadaCliente(jTabela_Cliente);
            }
        }
    }
    );
    jScrollPane3.setViewportView(jTabela_Cliente);

    getContentPane().add(jScrollPane3);
    jScrollPane3.setBounds(30, 70, 220, 120);

    jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Selecione um Cliente", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
    getContentPane().add(jLabel4);
    jLabel4.setBounds(10, 10, 260, 200);

    try {
        jFTF_data.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }
    jFTF_data.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    getContentPane().add(jFTF_data);
    jFTF_data.setBounds(180, 250, 80, 20);

    jLabel6.setText("Data de locação:");
    getContentPane().add(jLabel6);
    jLabel6.setBounds(80, 250, 90, 20);

    jLabel7.setText("Ativo:");
    getContentPane().add(jLabel7);
    jLabel7.setBounds(320, 270, 34, 20);

    buttonGroup1.add(jRB_sim);
    jRB_sim.setText("Sim");
    getContentPane().add(jRB_sim);
    jRB_sim.setBounds(370, 260, 93, 20);

    buttonGroup1.add(jRB_nao);
    jRB_nao.setText("Não");
    getContentPane().add(jRB_nao);
    jRB_nao.setBounds(370, 290, 93, 20);

    jB_salvar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    jB_salvar.setText("Locar");
    jB_salvar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_salvarActionPerformed(evt);
        }
    });
    getContentPane().add(jB_salvar);
    jB_salvar.setBounds(310, 360, 120, 40);

    jB_devolver.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    jB_devolver.setText("Devolver");
    jB_devolver.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_devolverActionPerformed(evt);
        }
    });
    getContentPane().add(jB_devolver);
    jB_devolver.setBounds(700, 360, 120, 40);

    jB_novo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    jB_novo.setText("Novo");
    jB_novo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_novoActionPerformed(evt);
        }
    });
    getContentPane().add(jB_novo);
    jB_novo.setBounds(110, 360, 120, 40);

    jB_voltar1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    jB_voltar1.setText("Voltar");
    jB_voltar1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_voltar1ActionPerformed(evt);
        }
    });
    getContentPane().add(jB_voltar1);
    jB_voltar1.setBounds(890, 360, 120, 40);

    jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
    getContentPane().add(jSeparator1);
    jSeparator1.setBounds(570, 10, 10, 400);

    jTabela_Operacao.setModel(tmOperacao);
    jTabela_Operacao.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lsmOperacao = jTabela_Operacao.getSelectionModel();
    lsmOperacao.addListSelectionListener(new ListSelectionListener(){
        public void valueChanged(ListSelectionEvent e){
            if(! e.getValueIsAdjusting()){
                JTTabelaLinhaSelecionadaOperacao(jTabela_Operacao);
            }
        }
    }
    );
    jScrollPane1.setViewportView(jTabela_Operacao);

    getContentPane().add(jScrollPane1);
    jScrollPane1.setBounds(590, 80, 500, 250);

    jTF_pesquisar.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            jTF_pesquisarKeyReleased(evt);
        }
    });
    getContentPane().add(jTF_pesquisar);
    jTF_pesquisar.setBounds(750, 30, 210, 20);

    jLabel8.setText("Data de Devolução:");
    getContentPane().add(jLabel8);
    jLabel8.setBounds(80, 300, 100, 14);

    try {
        jFTF_data_devolucao.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }
    jFTF_data_devolucao.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    getContentPane().add(jFTF_data_devolucao);
    jFTF_data_devolucao.setBounds(180, 295, 80, 20);

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-1120)/2, (screenSize.height-465)/2, 1120, 465);
    }// </editor-fold>//GEN-END:initComponents

    private void jTF_pesquisarFilmeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisarFilmeKeyReleased
        listFilme = loc.buscarListaDVDs(jTF_pesquisarFilme.getText() + "%");
        mostraPesquisaFilme(listFilme);
    }//GEN-LAST:event_jTF_pesquisarFilmeKeyReleased

    private void jTF_pesquisarClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTF_pesquisarClienteMouseClicked
        jTabela_Cliente.clearSelection();        // TODO add your handling code here:
    }//GEN-LAST:event_jTF_pesquisarClienteMouseClicked

    private void jTF_pesquisarClienteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisarClienteKeyReleased
        listCliente = loc.buscarClienteList(jTF_pesquisarCliente.getText() + "%");
        mostraPesquisaCliente(listCliente);
    }//GEN-LAST:event_jTF_pesquisarClienteKeyReleased

    private void jB_devolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_devolverActionPerformed
        if (jTabela_Operacao.getSelectedRow() > -1) {
            loc.devolverFilme(listOperacao.get(jTabela_Operacao.getSelectedRow()).getCpf(), listOperacao.get(jTabela_Operacao.getSelectedRow()).getCodigoDvd());
            System.out.println(listOperacao.get(jTabela_Operacao.getSelectedRow()).getCodigo());
            JOptionPane.showMessageDialog(null, "Devolução realizada com sucesso.");
            jTF_pesquisarKeyReleased(null);
        }
    }//GEN-LAST:event_jB_devolverActionPerformed

    private void jB_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_novoActionPerformed
        jTabela_Cliente.clearSelection();
        jTabela_Filme.clearSelection();
        
        buttonGroup1.clearSelection();
        jFTF_data.setText("");
        jFTF_data_devolucao.setText("");

    }//GEN-LAST:event_jB_novoActionPerformed

    private void jB_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_salvarActionPerformed
        if (VerificaDados()) {
//            System.out.println(listFilme.get(jTabela_Filme.getSelectedRow()).getCod_dvd() + "  Numero de locacoes: " + loc.LocacoesAtivas(listFilme.get(jTabela_Filme.getSelectedRow()).getCod_dvd()) + " numero q pode ser alocados: " + loc.buscarFilme(listFilme.get(jTabela_Filme.getSelectedRow()).getCod_dvd()).getNumeroCopias());
            //if (loc.LocacoesAtivas(listFilme.get(jTabela_Filme.getSelectedRow()).getCod_dvd()) < loc.buscarFilme(listFilme.get(jTabela_Filme.getSelectedRow()).getCod_dvd()).getNumeroCopias()) {
                Locacao operacaoLoc = new Locacao( listCliente.get(jTabela_Cliente.getSelectedRow()).getCpf(), listFilme.get(jTabela_Filme.getSelectedRow()).getFilme().getCodigo(), listFilme.get(jTabela_Filme.getSelectedRow()).getCod_dvd());
                try {
                    operacaoLoc.setData(formatarData(jFTF_data.getText()));
                    operacaoLoc.setDataDevolucao(formatarData(jFTF_data_devolucao.getText()));
                } catch (ParseException ex) {
                    Logger.getLogger(FormLocacao.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (jRB_sim.isSelected()) {
                    operacaoLoc.setAtivo(true);
                } else {
                    operacaoLoc.setAtivo(false);
                }
                
                loc.locarFilme(operacaoLoc);
                JOptionPane.showMessageDialog(null, "Filme locado com sucesso.");
                jTF_pesquisarKeyReleased(null);
                JOptionPane.showMessageDialog(null, "Gerando nota fiscal...");
                java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
                jDialog1.setBounds((screenSize.width - 625) / 2, (screenSize.height - 430) / 2, 625, 430);
                jDialog1.setVisible(true);
//            } else {
//                JOptionPane.showMessageDialog(null, "Todos as cópias ja foram locadas, efetue uma reserva.");
//            }
        } else {
            JOptionPane.showMessageDialog(null, "Campos não preenchidos.");
        }
    }//GEN-LAST:event_jB_salvarActionPerformed

    private void jB_voltar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_voltar1ActionPerformed
        dispose();
    }//GEN-LAST:event_jB_voltar1ActionPerformed

    private void jTF_pesquisarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisarKeyReleased

        listOperacao = loc.buscarLocacoesCliente(jTF_pesquisar.getText() + "%");
        mostraPesquisaLocacao(listOperacao);

    }//GEN-LAST:event_jTF_pesquisarKeyReleased

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed

        arquivo = jFileChooser1.getSelectedFile();


        jDialog1.setVisible(false);
        if (arquivo != null) {
            String adober;

            adober = String.valueOf(arquivo);
            File pasta = new File(adober + "/Relatorios");
            pasta.mkdir();
            adober = adober + "/Relatorios";
            System.out.println(adober);
            if (!adober.equals("null")) {
               loc.gerarNotaFiscal(adober,listCliente.get(jTabela_Cliente.getSelectedRow()).getNome(), listFilme.get(jTabela_Filme.getSelectedRow()).getCod_dvd() );
               
            }
            JOptionPane.showMessageDialog(rootPane, "Nota Fiscal gerada com sucesso.");
        }
    }//GEN-LAST:event_jFileChooser1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new FormLocacao().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jB_devolver;
    private javax.swing.JButton jB_novo;
    private javax.swing.JButton jB_salvar;
    private javax.swing.JButton jB_voltar1;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JFormattedTextField jFTF_data;
    private javax.swing.JFormattedTextField jFTF_data_devolucao;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JRadioButton jRB_nao;
    private javax.swing.JRadioButton jRB_sim;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTF_pesquisar;
    private javax.swing.JTextField jTF_pesquisarCliente;
    private javax.swing.JTextField jTF_pesquisarFilme;
    private javax.swing.JTable jTabela_Cliente;
    private javax.swing.JTable jTabela_Filme;
    private javax.swing.JTable jTabela_Operacao;
    // End of variables declaration//GEN-END:variables

    private void mostraPesquisaCliente(List<Cliente> listCliente) {
        while (tmCliente.getRowCount() > 0) {
            tmCliente.removeRow(0);
        }
        if (!listCliente.isEmpty()) {
            String[] linha = new String[]{null};
            for (int i = 0; i < listCliente.size(); i++) {
                tmCliente.addRow(linha);
                tmCliente.setValueAt(listCliente.get(i).getNome(), i, 0);
            }
        }
    }

    private void mostraPesquisaFilme(List<DVD> listFilme) {
        while (tmFilme.getRowCount() > 0) {
            tmFilme.removeRow(0);
        }
        if (!listFilme.isEmpty()) {
            String[] linha = new String[]{null};
            for (int i = 0; i < listFilme.size(); i++) {
                tmFilme.addRow(linha);
                tmFilme.setValueAt(listFilme.get(i).getFilme().getTitulo(), i, 0);

            }
        }
    }

    private void JTTabelaLinhaSelecionadaCliente(JTable tabela) {
    }

    private void JTTabelaLinhaSelecionadaFilme(JTable tabela) {
    }

    private void JTTabelaLinhaSelecionadaOperacao(JTable tabela) {
        if (jTabela_Operacao.getSelectedRow() > -1) {
            if (listOperacao.get(tabela.getSelectedRow()).isAtivo()) {
                jB_devolver.setVisible(true);
            } else {
                jB_devolver.setVisible(false);
            }
        }
    }

    private boolean VerificaDados() {
        if ( jTabela_Filme.getSelectedRow() < -1 || jTabela_Cliente.getSelectedRow() < -1) {
            return false;
        } else {
            return true;
        }
    }

    private Date formatarData(String data) throws ParseException {
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        return new Date(formatter.parse(data).getTime());

    }

    private void mostraPesquisaLocacao(List<Locacao> listOperacao) {
        while (tmOperacao.getRowCount() > 0) {
            tmOperacao.removeRow(0);
        }
        if (!listOperacao.isEmpty()) {
            String[] linha = new String[]{null, null, null};
            for (int i = 0; i < listOperacao.size(); i++) {
                tmOperacao.addRow(linha);
                tmOperacao.setValueAt(loc.buscarCliente(listOperacao.get(i).getCpf()).getNome(), i, 0);
                tmOperacao.setValueAt(loc.buscarFilme(listOperacao.get(i).getCodigo()).getTitulo(), i, 1);
                
//                if (loc.buscarLocacao(listOperacao.get(i).getCpf(), listOperacao.get(i).getCodigo()).isAtivo()) {
//                    tmOperacao.setValueAt("Sim", i, 2);
//                } else {
//                    tmOperacao.setValueAt("Não", i, 2);
//                }
                if(listOperacao.get(i).isAtivo()){
                    tmOperacao.setValueAt("Sim", i, 2);
                }else{
                    tmOperacao.setValueAt("Não", i, 2);
                }
            }
        }
    }
}
